package com.shop.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.mapper.Sms_Sku_Full_Reduction_Mapper;
import com.shop.mapper.Sms_Sku_Ladder_Mapper;
import com.shop.pojo.sms.Sms_Seckill_Sku_Relation;
import com.shop.pojo.sms.Sms_Sku_Full_Reduction;
import com.shop.service.Sms_Sku_Ladder_Service;
import com.shop.pojo.sms.Sms_Sku_Ladder;
import com.shop.utils.R;
import com.shop.utils.Sku_ManJian;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//商品阶梯业务层
@Service
public class Sms_Sku_Ladder_ServiceImpl extends ServiceImpl<Sms_Sku_Ladder_Mapper, Sms_Sku_Ladder> implements Sms_Sku_Ladder_Service {

    @Autowired
    private Sms_Sku_Ladder_Mapper sms_sku_ladder_mapper;

    //注入商品满减的持久层
    @Autowired
    private Sms_Sku_Full_Reduction_Mapper sms_sku_full_reduction_mapper;
    /**
     * 后台显示优惠卷满减活动信息
     * @param sku_id
     * @return
     */
    @Override
    public Sku_ManJian find_admin_ManJian_All(Long sku_id) {
        return sms_sku_ladder_mapper.find_admin_ManJian_All(sku_id);
    }

    /***
     * 后台修改关联商品的优惠卷满减信息  修改 满减优惠 和 商品阶梯价钱
     * @param sku_manJian
     * @return
     */
    @Transactional
    @Override
    public R up_admin_ManJian_All(Sku_ManJian sku_manJian) {
        //商品阶梯价格的修改
        Sms_Sku_Ladder sms_sku_ladder = new Sms_Sku_Ladder();//创建商品阶梯价格
        sms_sku_ladder.setFull_count(sku_manJian.getFull_count());//满几件
        sms_sku_ladder.setDiscount(sku_manJian.getDiscount());//打几折
        sms_sku_ladder.setPrice(sku_manJian.getPrice());//折后价钱
        sms_sku_ladder.setAdd_other(sku_manJian.getAdd_others());//是否叠加其他优惠
        sms_sku_ladder.setId(sku_manJian.getLadder_id());//主键标识进行修改操作
        int ladder = sms_sku_ladder_mapper.updateById(sms_sku_ladder);

        //商品满减活动的修改
        Sms_Sku_Full_Reduction sms_sku_full_reduction = new Sms_Sku_Full_Reduction();//创建商品满减优惠
        sms_sku_full_reduction.setFull_price(sku_manJian.getFull_price());//满多少钱
        sms_sku_full_reduction.setReduce_price(sku_manJian.getReduce_price());//减多少钱
        sms_sku_full_reduction.setAdd_other(sku_manJian.getAdd_other());//是否参与其他优惠
        sms_sku_full_reduction.setId(sku_manJian.getReduction_id());//主键ID
        int full = sms_sku_full_reduction_mapper.updateById(sms_sku_full_reduction);

        if(ladder > 0 && full > 0){
            return R.success();
        }
        return R.error(500,"修改失败");
    }
}
